package lesson06;



public class Test01 {
    public static void say(People people){
        people.intro();
        people.sayArea();
    }
    public static void main(String[] args) {
        People people = new People("张飞",20);
        people.intro();
        people.sayArea();

        ChinesePeople chinesePeople = new ChinesePeople("关羽",30);
        chinesePeople.intro();
        chinesePeople.sayArea();
        chinesePeople.play();

        JapanesePeople japanesePeople = new JapanesePeople("山本五十六",40);
        japanesePeople.intro();
        japanesePeople.sayArea();

        // 向上转型后，通过父类类型的变量就无法访问子类特有的属性和方法
        // （这些方法只是看不见，并不是消失了）
        People people1 = new ChinesePeople("曹操",50);
        people1.intro();
        people1.sayArea();
//        people1.play()

        // 向下转型必须使用()进行强转，但是强转可能发生转换类型的错误
        // 因此，在向下转型之前可以使用instanceof进行类型的判断

//        if(people1 instanceof ChinesePeople){
//            ChinesePeople chinesePeople1 = (ChinesePeople) people1;
//            chinesePeople1.play();
//        }else{
//            System.out.println("对不起类型不对");
//        }
//        if(people1 instanceof JapanesePeople){
//            JapanesePeople japanesePeople1 = (JapanesePeople) people1;
//            japanesePeople1.eat();
//        }else{
//            System.out.println("对不起类型不对");
//        }

        say(people);
        say(chinesePeople);
        say(japanesePeople);
        say(new KoreaPeople("思密达",30));
    }
}
